$(function() {
    /**
      系统设置
    **/
    function doSysSettings(processName, processId, parameterName, parameterId, componentName, componentId) {
        $.ajax({
                url: '../json/getTask.json',
                type: 'get',
                // dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
                data: {
                    method: 'doSysSettings',
                    processName: processName,
                    processId: processId,
                    parameterName: parameterName,
                    parameterId: parameterId,
                    componentName: componentName,
                    componentId: componentId
                },
            })
            .done(function(data) {
                console.log("doSysSettings");
            })
            .fail(function() {
                console.log("error");
            })
    }
    doSysSettings();


    $("body").on('click', '.doSysSettings', function(event) {
        event.preventDefault();
        /* Act on the event */
        var processName = $(".processName").val();
        var processId = $(".processId").val();
        var parameterName = $(".parameterName").val();
        var parameterId = $(".parameterId").val();
        var componentName = $(".componentName").val();
        var componentId = $(".componentId").val();
        layer.confirm('是否进行添加？', function(index) {
            //do something
            doSysSettings(processName, processId, parameterName, parameterId, componentName, componentId);
            layer.close(index);
            window.location.reload();
        });

    });

    /**
      查找系统设置
    **/
    function getSysSettings() {
        $.ajax({
                url: '../json/getSysSettings.json',
                type: 'get',
                // dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
                data: { method: 'getSysSettings' },
            })
            .done(function(data) {
                console.log("getSysSettings");
                var data = data.data;
                var html = "";

                for (var i = 0; i < data.length; i++) {
                    html += `<tr><td rowspan="3">${data[i].processName}</td>
                            <td>${data[i].paramChildren[0].parameterName}</td>
                            <td>${data[i].paramChildren[0].parameterId}</td>
                            <td>${data[i].componChildren[0].componentName}</td>
                            <td>${data[i].componChildren[0].componentId}</td>
                            </tr>`;
                            for (var j = 1; j < data[i].paramChildren.length; j++) {
                                html+=`<tr>
                             <td>${data[i].paramChildren[j].parameterName}</td>
                            <td>${data[i].paramChildren[j].parameterId}</td>
                             <td>${data[i].componChildren[j].componentName}</td>
                            <td>${data[i].componChildren[j].componentId}</td></tr>
                            `;
                            }
 
                }
                console.log(html)
                $(html).appendTo('.process');
            })
            .fail(function() {
                console.log("error");
            })
    }
    getSysSettings();

})